<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组合函数</title>
</head>
<body>
    <script>
        //组合函数实现函数的组合调用
        function add(x)
        {
            return x+5;
        }
        function double(x)
        {
            return x**2;
        }
       console.log(  double(add(1)));
       
       //组合函数封装
       function compose(...fn)
       {
          return function(x)
          {
             var result = x;
             for(var i = 0;i<fn.length;i++)
             {
                  result = fn[i](result);
             }

             return result;
          }
       }
       var composeFun = compose(add,double);
       var ret = composeFun(1);
       console.log(ret);

    </script>
</body>
</html>